package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.dao.TaobaoSchemeMapper;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.entity.TaobaoScheme;
import com.eco.fanliapp.service.ITaobaoSchemeService;
import com.eco.fanliapp.service.RedisTemplateService;
import com.eco.fanliapp.utils.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 联盟账号 服务层实现
 * 
 * @author xiaoxx
 * @date 2019-05-12
 */
@Service
public class TaobaoSchemeServiceImpl extends ServiceImpl<TaobaoSchemeMapper, TaobaoScheme> implements ITaobaoSchemeService
{
	@Autowired
	private TaobaoSchemeMapper taobaoSchemeMapper;

	@Autowired
	private RedisTemplateService redisTemplateService;

	/**
	 * 查询联盟账号信息-优先从redis中获取
	 *
	 * @param id   联盟账号ID
	 * @param type 0实时从数据库1优先从redis
	 * @return 联盟账号信息
	 */
	@Override
	public TaobaoScheme selectTaobaoSchemeById(Integer id, int type) {
		String redisKeyStr = "app_taobaoschemeById_" + id;
		TaobaoScheme taobaoScheme = null;
		if (type == 1 && redisTemplateService.hasKey(redisKeyStr) ) {
			taobaoScheme = redisTemplateService.getTByKey(redisKeyStr, TaobaoScheme.class);
		}
		if (taobaoScheme == null) {
			taobaoScheme = taobaoSchemeMapper.selectTaobaoSchemeById(id);
			if (taobaoScheme != null) {
				redisTemplateService.set(redisKeyStr, taobaoScheme, 60 * 5);
			}
		}
		return taobaoScheme;
	}

	/**
     * 查询联盟账号信息
     * 
     * @param id 联盟账号ID
     * @return 联盟账号信息
     */
    @Override
	public TaobaoScheme selectTaobaoSchemeById(Integer id)
	{
	    return taobaoSchemeMapper.selectTaobaoSchemeById(id);
	}
	
	/**
     * 查询联盟账号列表
     * 
     * @param taobaoScheme 联盟账号信息
     * @return 联盟账号集合
     */
	@Override
	public List<TaobaoScheme> selectTaobaoSchemeList(TaobaoScheme taobaoScheme)
	{
	    return taobaoSchemeMapper.selectTaobaoSchemeList(taobaoScheme);
	}
	/**
	 * 查询联盟账号列表不重复
	 *
	 * @param taobaoScheme 联盟账号信息
	 * @return 联盟账号集合
	 */
	@Override
	public List<TaobaoScheme> selectDistinctTaobaoSchemeList(TaobaoScheme taobaoScheme)
	{
		return taobaoSchemeMapper.selectDistinctTaobaoSchemeList(taobaoScheme);
	}

	@Override
	public List<TaobaoScheme> selectDistinctTaobaoScheme(TaobaoScheme taobaoScheme)
	{
		return taobaoSchemeMapper.selectDistinctTaobaoScheme(taobaoScheme);
	}

    /**
     * 新增联盟账号
     * 
     * @param taobaoScheme 联盟账号信息
     * @return 结果
     */
	@Override
	public int insertTaobaoScheme(TaobaoScheme taobaoScheme)
	{
	    return taobaoSchemeMapper.insertTaobaoScheme(taobaoScheme);
	}
	
	/**
     * 修改联盟账号
     * 
     * @param taobaoScheme 联盟账号信息
     * @return 结果
     */
	@Override
	public int updateTaobaoScheme(TaobaoScheme taobaoScheme)
	{
	    return taobaoSchemeMapper.updateTaobaoScheme(taobaoScheme);
	}

	/**
     * 删除联盟账号对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteTaobaoSchemeByIds(String ids)
	{
		return taobaoSchemeMapper.deleteTaobaoSchemeByIds(Convert.toStrArray(ids));
	}

	@Override
	public TaobaoScheme findTaobaoSchemeOrderSession() {
		// TODO Auto-generated method findTaobaoSchemeOrderSession
		return taobaoSchemeMapper.findTaobaoSchemeOrderSession();
	}
	
}
